<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="../../mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>设备列表</title>
    <t:base type="jquery"></t:base>
    <script type="text/javascript" src="webpage/com/wx/added_product/procurement/shoppingCar.js"></script>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

    <script type="text/javascript" charset="utf-8">
        mui.init();
    </script>

</head>
<body>
<div class="tel"><a href="tel:400-88-22726"> <img src="${webRoot }images/tel.jpg"></a></div>
<div class="chanp chanpp" style="margin-top: 0; margin-bottom: 70px;">
    <ul class="mui-table-view" id="equipUl">
        <script type="text/jTemplate" id="equipTemplate">
            {#foreach $T as Item}
            <li class="mui-table-view-cell" style="margin-top:0px;">
                <div class=" mui-checkbox mui-left li_f mui-clearfix">
                    <input name="checkbox" type="checkbox" value="{$T.Item.id}" data-bp="{$T.Item.bpNo}"
                           style="left:3px;" class="checkbox1">
                    <div class="gd edd inrr" style="width:80%">
                        <h4 class="sn">序列号：{$T.Item.sn.toString()}</h4>
                        <h4 class="type-desc">机型：{$T.Item.typeDesc}</h4>
                    </div>
                </div>
            </li>
            {/#for}
        </script>

    </ul>
</div>
<div class="mui-input-row mui-checkbox mui-left  quanx" style="text-align: center">
    <h3 style="margin-left:40%;">
        <a id="btn_confirm" style="margin-right:55%;width:120px;">确定</a>
    </h3>
</div>
<script type="text/javascript">

    function initLiClick(){
        $("#equipUl li").find(".gd").click(function(){
            var _check = $(this).siblings(":checkbox");
            _check.attr("checked",!_check.is(":checked"));
        })
    }
    function initEquipList(){
        $.getJSON("zyEquipmentSpareController.do?getEquipByCinema",{cinemaId:'${cinemaId}'},function(data){
            $("#equipUl").setTemplate($("#equipTemplate").html()).processTemplate(data);
            initLiClick();
            var selectedEquip = localStorage.getItem("selectedEquip");
            if(!$.isEmptyObject(selectedEquip)){
                selectedEquip = $.parseJSON(selectedEquip);
                $.each(selectedEquip,function(idx,itm){
                    $("input[value='"+itm.id+"']").attr("checked","checked");
                })
            }
        })
    }

    $(function () {

        initEquipList();
        initLiClick();

        $("#btn_confirm").click(function () {
            var sel = new Array();
            var idArray = new Array();
            $(":checked").each(function(){
                var o = $(this);
                idArray.push(o.val());
                sel.push({
                    id : o.val(),
                    bpNo : o.attr("data-bp"),
                    sn : o.siblings("div").find(".sn").text(),
                    desc : o.siblings("div").find(".type-desc").text()
                });
            })
            if(idArray.length > 0){
                var re = true;
                $.ajax({
                    async: false,
                    url: "cbsProcurementNoteController.do?inspectEquipment",
                    data: {esIdStr: idArray.join(",")},
                    success: function (data) {
                        if (!$.isEmptyObject(data) && data != "\"0\"") {
                            var msg = "所选设备不正确";
                            if(data == "\"1\""){
                                msg = "选择的设备所属BP不一致";
                            }else if(data == "\"2\""){
                                msg = "选择的设备中存在在保和不在保的"
                            }else{

                            }
                            mui.alert(msg, "订单提示");
                            re = false;
                        }
                    }
                })
            }else{
                localStorage.removeItem("selectedEquip");
            }
            if(re){
                localStorage.setItem("selectedEquip", JSON.stringify(sel));
            }
            mui.back();
        })

    })

</script>
</body>
</html>